package com.part2.business.function.Impl;

import java.util.List;

import com.part2.action.common.validator.Validator;
import com.part2.beans.Users;
import com.part2.common.query.Page;
import com.part2.dao.common.BaseDao;
import com.part2.dao.function.UserDao;

public class UserServiceImpl implements com.part2.business.function.UsersService {

	private BaseDao<Users, String> baseDao;
	private UserDao userDao;

	public void setBaseDao(BaseDao<Users, String> baseDao) {
		this.baseDao = baseDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void addUsers(Users users) {
		// TODO Auto-generated method stub
		baseDao.save(users);
	}

	public void deleteUsers(String id) {
		// TODO Auto-generated method stub
		if (Validator.isNotNull(id)) {
			Users us = this.findUsersByPrimeKey(id);
			if (us != null)
				baseDao.delete(us);
		}
	}

	public List<Users> findUsers() {
		// TODO Auto-generated method stub
		return baseDao.findAll(Users.class);
	}

	public Page<Users> findUsers(Page<Users> page) {
		// TODO Auto-generated method stub
		return userDao.findUsers(page);
	}

	public Users findUsersByPrimeKey(String id) {
		// TODO Auto-generated method stub
		return userDao.findUsersByPrimeKey(id);
	}

	public void updateUsers(Users users) {
		// TODO Auto-generated method stub
		baseDao.saveOrUpdate(users);
	}

}
